package com.tfjybj.itoo.exam.provider.controller;


import com.dmsdbj.itoo.tool.business.ItooResult;
import com.github.pagehelper.PageInfo;
import com.tfjybj.itoo.exam.entity.QuestionEntity;
import com.tfjybj.itoo.exam.model.*;
import com.tfjybj.itoo.exam.provider.service.QuestionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.apache.poi.hwpf.HWPFDocument;
import org.apache.poi.hwpf.usermodel.Range;
import org.apache.poi.xwpf.extractor.XWPFWordExtractor;
import org.apache.poi.xwpf.usermodel.XWPFDocument;
import org.springframework.beans.BeanUtils;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.List;


/**
 * QuestionController
 * question表
 *
 * @author 李青松
 * @version 2.0.0
 * @since 2.0.0 2018-11-01 08:55:53
 */
@Api(tags = {"question表接口"})
@RequestMapping(value = "/question")
@RestController
@Slf4j
public class QuestionController {

    @Resource
    private QuestionService questionService;

    //region 模板生成：基本增删改

    /**
     * 添加
     *
     * @param model QuestionModel
     * @return 添加的结果
     * @author 李青松
     * @since 2.0.0 2018-11-01 08:55:53
     */
    @ApiOperation(value = "添加")
    @PostMapping(value = {"/create"})
    public ItooResult create(@RequestBody QuestionModel model) {
        if (StringUtils.isEmpty(model.getSerial())) {
            return ItooResult.build(ItooResult.FAIL, "serial为空");
        }
        if (StringUtils.isEmpty(model.getQuestionTypeId())) {
            return ItooResult.build(ItooResult.FAIL, "questionTypeId为空");
        }
        if (StringUtils.isEmpty(model.getQuestionClassifyId())) {
            return ItooResult.build(ItooResult.FAIL, "questionClassifyId为空");
        }
        if (StringUtils.isEmpty(model.getQuestionContentHtml())) {
            return ItooResult.build(ItooResult.FAIL, "questionContentHtml为空");
        }
        if (StringUtils.isEmpty(model.getAnswerHtml())) {
            return ItooResult.build(ItooResult.FAIL, "answerHtml为空");
        }
        if (StringUtils.isEmpty(model.getSource())) {
            return ItooResult.build(ItooResult.FAIL, "source为空");
        }
        if (StringUtils.isEmpty(model.getCourseId())) {
            return ItooResult.build(ItooResult.FAIL, "courseId为空");
        }
        QuestionEntity questionEntity = new QuestionEntity();
        BeanUtils.copyProperties(model, questionEntity);
        questionService.save(questionEntity);
        return ItooResult.build(ItooResult.SUCCESS, "添加成功");
    }


    /**
     * 删除
     *
     * @param id 主键id
     * @return ItooResult 是否删除成功
     * @author 李青松
     * @since 2.0.0 2018-11-01 08:55:53
     */
    @ApiOperation(value = "根据id删除（单个）")
    @DeleteMapping(value = {"/delete/{id}"})
    public ItooResult delete(@ApiParam(value = "主键id", required = true) @PathVariable String id) {
        questionService.removeById(id);
        return ItooResult.build(ItooResult.SUCCESS, "删除成功");
    }

    /**
     * 批量删除
     *
     * @param ids ids
     * @return ItooResult 批量删除是否成功结果
     * @author 李青松
     * @since 2.0.0 2018-11-01 08:55:53
     */
    @ApiOperation(value = "根据id批量删除")
    @DeleteMapping(value = {"/deleteByIds"})
    @ApiImplicitParam(name = "ids", value = "ids", dataType = "List<String>", required = true)
    public ItooResult deleteByIds(@RequestBody List<String> ids) {
        questionService.removeByIds(ids);
        return ItooResult.build(ItooResult.SUCCESS, "批量删除成功");
    }

    /**
     * 修改
     *
     * @param model QuestionModel
     * @return 修改后的结果
     * @author 李青松
     * @since 2.0.0 2018-11-01 08:55:53
     */
    @ApiOperation(value = "根据id修改question")
    @PutMapping(value = {"/modify"})
    public ItooResult modify(@RequestBody QuestionModel model) {
        if (StringUtils.isEmpty(model.getSerial())) {
            return ItooResult.build(ItooResult.FAIL, "serial为空");
        }
        if (StringUtils.isEmpty(model.getQuestionTypeId())) {
            return ItooResult.build(ItooResult.FAIL, "questionTypeId为空");
        }
        if (StringUtils.isEmpty(model.getQuestionClassifyId())) {
            return ItooResult.build(ItooResult.FAIL, "questionClassifyId为空");
        }
        if (StringUtils.isEmpty(model.getQuestionContentHtml())) {
            return ItooResult.build(ItooResult.FAIL, "questionContentHtml为空");
        }
        if (StringUtils.isEmpty(model.getAnswerHtml())) {
            return ItooResult.build(ItooResult.FAIL, "answerHtml为空");
        }
        if (StringUtils.isEmpty(model.getSource())) {
            return ItooResult.build(ItooResult.FAIL, "source为空");
        }
        if (StringUtils.isEmpty(model.getCourseId())) {
            return ItooResult.build(ItooResult.FAIL, "courseId为空");
        }
        QuestionEntity questionEntity = new QuestionEntity();
        BeanUtils.copyProperties(model, questionEntity);
        questionService.updateById(questionEntity);
        return ItooResult.build(ItooResult.SUCCESS, "修改成功");
    }

    /**
     * 根据id查找Question
     *
     * @param id 主键id
     * @return 根据id查找Question
     * @author 李青松
     * @since 2.0.0 2018-11-01 08:55:53
     */
    @ApiOperation(value = "根据id查询")
    @GetMapping(value = {"/findById/{id}"})

    public ItooResult findById(@ApiParam(value = "主键id", required = true) @PathVariable String id) {
        QuestionEntity questionEntity = questionService.getById(id);
        return ItooResult.build(ItooResult.SUCCESS, "查询成功", questionEntity);
    }

    /**
     * @param pageNo   页码
     * @param pageSize 每页条数
     * @return 分页查询所有Question     *
     * @author 李青松
     * @since 2.0.0 2018-11-01 08:55:53
     */
    @ApiOperation(value = "分页查询所有Question")
    @GetMapping(value = {"/queryPageAll/{pageNo}/{pageSize}"})
    public ItooResult queryPageAll(@ApiParam(name = "pageNo", value = "页码", required = true, example = "1") @PathVariable Integer pageNo,
                                   @ApiParam(name = "pageSize", value = "页数", required = true, example = "10") @PathVariable Integer pageSize) {
        PageInfo<QuestionEntity> questions = questionService.queryPageAll(pageNo, pageSize);
        return ItooResult.build(ItooResult.SUCCESS, "查询成功", questions);
    }

    /**
     * 根据编号模糊查询question
     *
     * @param serial   编号
     * @param pageNo   页码
     * @param pageSize 页数
     * @return 模糊查询的question
     * @author 李青松
     * @since 2.0.0 2018-11-01 08:55:53
     */
    @ApiOperation(value = "根据编号模糊查询question", notes = "分页根据编号模糊查询question")
    @GetMapping(value = "queryQuestionByLikeSerial/{pageNo}/{pageSize}")
    public ItooResult queryQuestionByLikeSerial(@RequestParam(required = false, defaultValue = "") String serial,
                                                @ApiParam(name = "pageNo", value = "页码", required = true, example = "1") @PathVariable Integer pageNo,
                                                @ApiParam(name = "pageSize", value = "页数", required = true, example = "10") @PathVariable Integer pageSize) {
        PageInfo<QuestionEntity> questionList = questionService.queryByLikeSerial(serial, pageNo, pageSize);
        return ItooResult.build(ItooResult.SUCCESS, "查询成功", questionList);
    }
    //endregion

    /* **********************************以下为非模板生成的内容********************************* */


    /**
     * 添加试题（任意题型）
     *
     * @param model QuestionModel
     * @return 添加的结果
     * @author 郭凯
     * @since 2.0.0 2018-11-01 08:55:53
     */
    @ApiOperation(value = "添加试题")
    @PostMapping(value = {"/createQuestion"})
    public ItooResult createQuestion(@RequestBody List<QuestionAddModel> model) {
        return questionService.createQuestion(model);
    }


    /**
     * 根据题干实体查询试题集合
     *
     * @param questionEntity 题干实体
     * @return 试题集合
     * @author 郭凯
     * @since 2.0.0 2018-11-8 14:29:10
     */
    @ApiOperation(value = "查询试题集合")
    @PostMapping(value = "/Question")
    public ItooResult queryQuestion(@RequestBody QuestionEntity questionEntity) {
        List<QueryQuestionModel> questionModelList = questionService.queryByEntity(questionEntity);
        if (questionModelList == null) {
            return ItooResult.build(ItooResult.SUCCESS, "暂无数据", null);
        } else {
            return ItooResult.build(ItooResult.SUCCESS, "查询成功", questionModelList);
        }
    }


    /**
     * 根据题干实体查询试题集合
     *
     * @param operator 操作人
     * @return result
     * @author 郭凯
     * @since 2.0.0 2018-12-8 14:29:10
     */
    @ApiOperation(value = "题库首页查询试题")
    @PostMapping(value = "/queryQuestionByOperator/{pageNo}/{pageSize}")
    public ItooResult queryQuestionByOperator(
            @ApiParam(value = "操作人", required = true) @RequestParam String operator,
            @ApiParam(name = "pageNo", value = "页码", required = true, example = "1") @PathVariable Integer pageNo,
            @ApiParam(name = "pageSize", value = "页数", required = true, example = "10") @PathVariable Integer pageSize
    ) {
        PageInfo<QuestionModelForHomePage> queryQuestionModelPageInfo = questionService.queryQuestionModelPageInfo(pageNo, pageSize, operator);
        return ItooResult.build(ItooResult.SUCCESS, "查询成功", queryQuestionModelPageInfo);
    }


    /**
     * 题库检查点6: 分页 检查重复试题.--------所有题型
     *
     * @param operator       操作人
     * @param questionTypeId 题型id
     * @return fooGroup集合
     * @author 杜雨
     * @since 1.0.0 2019年5月29日15:22:10
     */
    @ApiOperation(value = "分页查询 检查重复试题")
    @GetMapping(value = {"/checkRepeatedQuestionsPage/{operator}/{questionTypeId}/{pageNo}/{pageSize}"})
    public ItooResult checkRepeatedQuestionsPage(
            @ApiParam(value = "操作人", required = true) @PathVariable String operator,
            @ApiParam(value = "题目类型", required = true) @PathVariable String questionTypeId,
            @ApiParam(name = "pageNo", value = "页码", required = true, example = "1") @PathVariable Integer pageNo,
            @ApiParam(name = "pageSize", value = "页数", required = true, example = "10") @PathVariable Integer pageSize) {
        PageInfo<QuestionModelForHomePage> result = questionService.checkRepeatedQuestionsPageInfo(pageNo, pageSize, operator,questionTypeId);

        return ItooResult.build(ItooResult.SUCCESS, "查询成功", result);
    }

    /**
     * 题库检查点6: 检查重复试题.--------所有题型
     *
     * @param operator       操作人
     * @param questionTypeId 题型id
     * @return fooGroup集合
     * @author 邓立瑶
     * @since 1.0.0 2018年11月9日16:40:36
     */
    @ApiOperation(value = "检查重复试题")
    @GetMapping(value = {"/checkRepeatedQuestions/{operator}/{questionTypeId}"})
    public ItooResult checkRepeatedQuestions(
            @ApiParam(value = "操作人", required = true) @PathVariable String operator,
            @ApiParam(value = "题目类型", required = true) @PathVariable String questionTypeId) {
        List<QuestionModelForHomePage> result = questionService.checkRepeatedQuestions(operator, questionTypeId);
        return ItooResult.build(ItooResult.SUCCESS, "查询成功", result);
    }


    /**
     * 删除单个试题
     *
     * @param id 试题id
     * @return ItooResult
     * @author 郭凯
     * @since 2.0.0 2018年11月9日16:40:36
     */
    @ApiOperation(value = "根据id删除试题和选项")
    @DeleteMapping(value = {"/updateIsDelete/{id}"})
    public ItooResult updateIsDelete(@ApiParam(value = "主键id", required = true) @PathVariable String id) {
        if (StringUtils.isEmpty(id)) {
            log.warn("题型id为空");
            return ItooResult.build(ItooResult.FAIL, "题型id为空");
        }
        boolean flag = questionService.updateIsDelete(id);
        if (flag) {
            return ItooResult.build(ItooResult.SUCCESS, "删除成功");
        } else {
            return ItooResult.build(ItooResult.FAIL, "删除失败，请重试");
        }
    }

    /**
     * 查询试题分类名称
     *
     * @param operator 操作人
     * @return ItooResult
     * @author 郭凯
     * @since 2.0.0 2018-11-21 11:32:21
     */
    @ApiOperation(value = "查询试题分类名称")
    @PostMapping(value = "/operator")
    public ItooResult queryQuestionTypeName(String operator, String questionTypeId) {
        if (StringUtils.isEmpty(operator)) {
            log.warn("操作员operator为空");
            return ItooResult.build(ItooResult.FAIL, "操作员operator为空");
        }
        if (StringUtils.isEmpty(questionTypeId)) {
            log.warn("题型questionTypeId为空");
            return ItooResult.build(ItooResult.FAIL, "题型questionTypeId为空");
        }

        List<QueryQuestionTypeModel> queryQuestionTypeModelList = questionService.queryQuestionTypeName(operator, questionTypeId);
        if (queryQuestionTypeModelList != null) {
            return ItooResult.build(ItooResult.SUCCESS, "查询成功", queryQuestionTypeModelList);
        } else {

            return ItooResult.build(ItooResult.FAIL, "数据跑丢了");
        }
    }


    /**
     * 查询试题分类名称
     *
     * @param questionTypeId     题型id
     * @param operator 操作人
     * @param courseId 课程id
     * @return 查询试题分类的 questionClassify
     * @author 杨海云
     * @since 2.0.0 2018-11-21 11:32:21
     */
    @ApiOperation(value = "按照试题分类和题型查询试题难度")
    @GetMapping(value = "/queryQuestionDegree/{questionTypeId}/{operator}/{courseId}")
    public ItooResult queryQuestionDegree(
            @ApiParam(value = "题型id", required = true) @PathVariable String questionTypeId,
            @ApiParam(value = "操作人" ,required=true) @PathVariable String operator,
            @ApiParam(value = "课程id") @PathVariable String courseId,
            @RequestParam( required = false ,defaultValue = "") String questionClassifyId
    ) {

        List<QuestionModel> digits = questionService.queryQuestionDegree(questionTypeId,operator,courseId,questionClassifyId);
        return ItooResult.build(ItooResult.SUCCESS, "查询成功", digits);
    }

    /**
     * 根据试题内容模糊查询question
     *
     * @param content 试题内容
     * @return 模糊查询的question
     * @author 郭凯
     * @since 2.0.0 2018-11-01 08:55:53
     */
    @ApiOperation(value = "根据试题内容模糊查询question")
    @GetMapping(value = "queryQuestionByLikeContent/{pageNo}/{pageSize}")
    public ItooResult queryQuestionByLikeContent(@RequestParam(required = false, defaultValue = "") String content,
                                                 @RequestParam(required = false, defaultValue = "") String operator,
                                                 @ApiParam(name = "pageNo", value = "页码", required = true, example = "1") @PathVariable Integer pageNo,
                                                 @ApiParam(name = "pageSize", value = "页数", required = true, example = "10") @PathVariable Integer pageSize) {
        PageInfo<QuestionModelForHomePage> questionModelPageInfo = questionService.queryByLikeContent(content, operator, pageNo, pageSize);
        return ItooResult.build(ItooResult.SUCCESS, "查询成功", questionModelPageInfo);
    }


    /**
     * 根据id查找Question
     *
     * @param id 主键id
     * @return 根据id查找Question
     * @author 郭凯
     * @since 2.0.0 2018-12-1 15:53:12
     */
    @ApiOperation(value = "根据id查询")
    @GetMapping(value = {"/queryById/{id}"})

    public ItooResult queryById(@ApiParam(value = "主键id", required = true) @PathVariable String id) {
        if (StringUtils.isEmpty(id)) {
            log.warn("主键id为空");
            return ItooResult.build(ItooResult.FAIL, "主键id为空");
        }
        if (questionService.queryById(id) == null) {
            return ItooResult.build(ItooResult.FAIL, "暂无数据", null);
        } else {
            QuestionAddModel questionModel = questionService.queryById(id);
            return ItooResult.build(ItooResult.SUCCESS, "查询成功", questionModel);
        }
    }


    /**
     * 设置必抽题
     *
     * @param operator       操作人
     * @param courseId       课程id
     * @param questionTypeId 题型id
     * @return 根据id查找Question
     * @author 郭凯
     * @since 2.0.0  2018-12-8 10:27:31
     */
    @ApiOperation(value = "根据题型、操作人和课程查询必抽题")
    @GetMapping(value = {"/queryById/{operator}/{courseId}/{questionTypeId}"})
    public ItooResult queryMustSelect(@ApiParam(value = "操作人", required = true) @PathVariable String operator,
                                      @ApiParam(value = "课程id", required = true) @PathVariable String courseId,
                                      @ApiParam(value = "题型id", required = true) @PathVariable String questionTypeId) {
        List<QueryQuestionModel> queryQuestionModelList = questionService.queryMustSelect(operator, courseId, questionTypeId);
        if (queryQuestionModelList.size() > 0) {
            return ItooResult.build(ItooResult.SUCCESS, "查询成功", queryQuestionModelList);
        } else {
            return ItooResult.build(ItooResult.FAIL, "查询失败");
        }
    }


    /**
     * 指导入试题
     *
     * @param multipartFile 文件
     * @param request       要求
     * @param response      返回
     * @param quesType      试题类型id
     * @param quesName      试题类型名称
     * @param courseId      课程id
     * @return itooResult 返回值
     * @author 侯旭日
     * @since 2.0.0 2018-11-28 19:40:28
     */
    @ApiOperation(value = "指导入试题", notes = "0001:部分成功；0000:成功；1111:失败")
    @PostMapping(value = {"/importByTemplate"})
    public ItooResult importByTemplate(@RequestParam(value = "file") MultipartFile multipartFile,
                                       HttpServletRequest request, HttpServletResponse response,
                                       @ApiParam(name = "quesType", value = "试题类型ID", required = true) @RequestParam(value = "quesType") String quesType,
                                       @ApiParam(name = "quesName", value = "试题类型名称", required = true) @RequestParam(value = "quesName") String quesName,
                                       @ApiParam(name = "courseId", value = "课程ID", required = true) @RequestParam(value = "courseId") String courseId,
                                       @ApiParam(name = "operator", value = "教师ID", required = true) @RequestParam(value = "operator") String operator) {
        return questionService.importTemplate(multipartFile, request, response, quesType, quesName, courseId, operator);
    }

    /**
     * 导出导入失败的试题
     * @param errorListId 导入未完成的key
     * @param response 导入请求
     * @return ItooResul
     * @author 李娜t
     */
    @ApiOperation(value="导出导入失败的试题")
    @GetMapping(value={"/exportErrorList/{errorListId}"})
    public ItooResult exportErrorList(@ApiParam(name = "errorListId", value = "errorListId", required = true) @PathVariable String errorListId, HttpServletResponse response)
    {
        if(questionService.exportErrorList(errorListId,response)){
            return ItooResult.build(ItooResult.SUCCESS,"导出成功");
      }else{
            return ItooResult.build(ItooResult.FAIL, "导出失败");
        }
    }

    /**
     * 根据操作人查询题型类型
     *
     * @param operator 操作人
     * @return ItooResult 根据操作人查询题型类型
     * @author 贾建清
     * @since 2.0.0 2018-12-13 16:02:36
     */
    @ApiOperation(value = "根据操作人查询题型类型")
    @GetMapping(value = {"/queryQuestionType/{operator}"})
    public ItooResult queryQuestionType(@ApiParam(value = "操作人", required = true) @PathVariable String operator
    ) {
        List<OperatorQuestionModel> questionModelList = questionService.queryQuestionType(operator);

        if (questionModelList.size() > 0) {
            return ItooResult.build(ItooResult.SUCCESS, "查询成功", questionModelList);
        } else {
            return ItooResult.build(ItooResult.FAIL, "查询失败");
        }
    }


    /**
     * 根据操作人和题型类型查询试题
     *
     * @param operator       操作员
     * @param questionTypeId  题型
     * @param pageNo 页码
     * @param pageSize 页数
     * @return ItooResult 根据操作人和题型类型查询试题
     * @author 贾建清
     * @since 2.0.0 2018-12-13 17:46:44
     */
    @ApiOperation(value = "根据操作人和题型类型查询试题")
    @GetMapping(value = {"/queryQuestion/{operator}/{questionTypeId}/{pageNo}/{pageSize}"})
    public ItooResult queryQuestion(@ApiParam(value = "操作人", required = true) @PathVariable String operator,
                                    @ApiParam(value = "题型id", required = true) @PathVariable(value = "questionTypeId") String[] questionTypeId,
                                    @ApiParam(name = "pageNo", value = "页码", required = true, example = "1") @PathVariable Integer pageNo,
                                    @ApiParam(name = "pageSize", value = "页数", required = true, example = "10") @PathVariable Integer pageSize
    ) {
        PageInfo<QuestionModel> questionModelList = questionService.queryQuestion(operator, questionTypeId, pageNo, pageSize);

        return ItooResult.build(ItooResult.SUCCESS, "查询成功", questionModelList);

    }

    /**
     * question_Classify 模糊查询必抽题
     *
     * @param searchInput    查询内容
     * @param courseId       课程id
     * @param questionTypeId 题型id
     * @param operator 操作人
     * @author 杨海云
     * @since 2.0.0 2018-12-5 13:27:08
     */
    @ApiOperation(value = "模糊查询必抽题")
    @GetMapping(value = "/indistinctQuestionClassify/{courseId}/{questionTypeId}/{operator}")
    public ItooResult indistinctQuestionClassify(
            @RequestParam(required = false, defaultValue = "") String searchInput,
            @ApiParam(value = "课程id", required = true) @PathVariable String courseId,
            @ApiParam(value = "题型id", required = true) @PathVariable String questionTypeId,
            @ApiParam(value = "操作人",required = true) @PathVariable String operator) {
        PageInfo<QuestionModel> questionModelPageInfo = questionService.indistinctQuestionClassify(searchInput, courseId, questionTypeId,operator);
        return ItooResult.build(ItooResult.SUCCESS, "查询成功", questionModelPageInfo);
    }


    /**
     * 根据课程/试题题型/分类查询试题
     *
     * @param questionEntity 试题实体
     * @param pageNo 页码
     * @param pageSize 页数
     * @return ItooResult 根据课程/试题题型/分类查询试题
     * @author 贾建清
     * @since 2.0.0 2018-12-16 14:55:14
     */
    @ApiOperation(value = "根据课程/试题题型/分类查询试题")
    @PostMapping(value = "/queryQuestionByType/{pageNo}/{pageSize}")
    public ItooResult queryQuestionByType(@RequestBody QuestionEntity questionEntity,
                                          @ApiParam(name = "pageNo", value = "页码", required = true, example = "1") @PathVariable Integer pageNo,
                                          @ApiParam(name = "pageSize", value = "页数", required = true, example = "10") @PathVariable Integer pageSize) {
        PageInfo<QuestionModelForHomePage> questionModelList = questionService.queryQuestionByType(questionEntity, pageNo, pageSize);

        return ItooResult.build(ItooResult.SUCCESS, "查询成功", questionModelList);
    }

    /**
     * 根据课程id查询题型
     *
     * @param courseId
     * @return
     * @author 李娜
     */
    @ApiOperation(value = "根据课程id查询题型")
    @GetMapping(value = "/queryQuestionTypeByCourse/{courseId}")
    public ItooResult queryQuestionTypeByCourse(@ApiParam(value = "课程id", required = true) @PathVariable String courseId) {
        List<QuestionTypeModel> questionTypeList = questionService.queryQuestionTypeByCourse(courseId);
        return ItooResult.build(ItooResult.SUCCESS, "查询成功", questionTypeList);
    }

    /**
     * 批量删除试题
     *
     * @param questionIds
     * @author 李娜
     */
    @ApiOperation(value = "批量删除试题")
    @DeleteMapping(value = "/DeleteQuestionBatch")
    public ItooResult deleteQuestionBatch(@ApiParam(value = "试题id", required = true) @RequestBody List<String> questionIds) {
        if (StringUtils.isEmpty(questionIds)) {
            log.warn("试题id为空");
            return ItooResult.build(ItooResult.FAIL, "试题id为空");
        }
        questionService.deleteQuestionBatch(questionIds);
        return ItooResult.build(ItooResult.SUCCESS, "删除成功");
    }


    /**
     * 检查json格式是否正确
     *
     * @param courseId   课程id
     * @param questionTypeId 题型id
     * @return ItooResult
     * @author 郭凯
     * @since 2.0.0  2019-1-16 15:14:38
     */
    @ApiOperation(value ="检查json格式是否正确")
    @PostMapping(value = "/checkJSON/{courseId}/{questionTypeId}")
    public ItooResult checkJSON(@ApiParam(value = "课程id", required = true) @PathVariable String courseId,
                                 @ApiParam(value = "题型id", required = true) @PathVariable String questionTypeId){

        return questionService.checkJSON(courseId,questionTypeId);
    }

    /**
     * 根据旧题id查询新题id
     *
     * @param questionId  旧题id
     * @return ItooResult
     * @author 郭凯
     * @since 2.0.0  2019-1-16 15:14:38
     */
    @ApiOperation(value ="根据旧题id查询新题id")
    @GetMapping("/selectNewQuestionById/{questionId}")
    public void selectNewQuestionById(@PathVariable String questionId){
        questionService.selectNewQuestionById(questionId);
    }

    /**
     * 根据课程id,题型id,章节id筛选题
     *
     * @param courseId           课程id
     * @param questionTypeId     试卷类型id
     * @param questionClassifyId 试卷分类
     * @param operator           登录人
     * @return 符合筛选条件的集合
     * @author 马莹
     * @since 2019-1-31 10:09:00
     */
    @ApiOperation(value = "根据课程id,题型id,章节id筛选题")
    @GetMapping(value = "/selectQuestion/{courseId}/{questionTypeId}/{questionClassifyId}/{operator}")
    public ItooResult selectQuestion(@PathVariable String courseId, @PathVariable String questionTypeId, @PathVariable String questionClassifyId, @PathVariable String operator) {
        List<QuestionMainModel> questionMainModels = questionService.selectQuestion(courseId, questionTypeId, questionClassifyId, operator);
        if (questionMainModels.size() > 0) {
            return ItooResult.build(ItooResult.SUCCESS, "查询成功!", questionMainModels);
        } else {
            return ItooResult.build(ItooResult.FAIL, "查询失败!");
        }
    }
    /**
     * 题库检查点: 检查重复试题编号
     *
     * @param serial       String
     * @return List
     * @author duyu
     * @since 2019年5月26日11:26:32
     */
    @ApiOperation(value = "检查重复试题编号")
    @GetMapping(value = {"/checkSerial/{serial}/{operator}"})
    public ItooResult checkSerial(
            @ApiParam(value = "试题编号", required = true) @PathVariable String serial,
            @ApiParam(value = "操作人", required = true) @PathVariable String operator) {
        List<QuestionEntity> result = questionService.checkSerial(serial,operator);
        Boolean flag=true;
        if (CollectionUtils.isEmpty(result)){
            flag=false;
        }
        return ItooResult.build(ItooResult.SUCCESS, "查询成功", flag);
    }

    @ApiOperation(value ="导入word")
    @PostMapping(value = "/importWord")
    public ItooResult importWord(@RequestParam("file") MultipartFile file, HttpServletRequest request, HttpServletResponse response){
        //获取文件名
        String fileName=file.getOriginalFilename();
        log.info("导入Word文档获取文件名："+fileName);
        //获取文件后缀
        String prefix=fileName.substring(fileName.lastIndexOf("."));
        log.info("获取文件后缀："+prefix);
        if (!".doc".equals(prefix.toLowerCase()) && !".docx".equals(prefix.toLowerCase())){
            return ItooResult.build(ItooResult.FAIL, "文件类型必须为.doc或.docx类型");
        }
        String doc1 =null;
        File wordFile=null;
        try {
            InputStream path=file.getInputStream();

            if(".docx".equals(prefix.toLowerCase())){
                XWPFDocument xdoc = new XWPFDocument(path);
                XWPFWordExtractor extractor = new XWPFWordExtractor(xdoc);
                doc1 = extractor.getText();
            }else if(".doc".equals(prefix.toLowerCase())){

                HWPFDocument doc = new HWPFDocument(path);
                String doc2 = doc.getDocumentText();
                System.out.println(doc2);
                StringBuilder doc3 = doc.getText();
                System.out.println(doc3);
                Range rang = doc.getRange();
                 doc1 = rang.text();
            }

            System.out.println(doc1);

        }catch (IOException e){
            log.error(""+e);
        }

        return ItooResult.build(ItooResult.SUCCESS,doc1);
    }



    //region  修改longBlob为longText 学习点参考

//    /**
//     * 修改longBlob为longText
//     *
//     * @return ItooResult
//     * @author 郭凯
//     * @since 2.0.0  2019-1-16 15:14:38
//     */
//    @ApiOperation(value ="根据旧题id查询新题id")
//    @GetMapping("/modifyHtml")
//    public ItooResult modifyHtml(){
//        boolean flag = questionService.modify();
//        if(flag){
//            return ItooResult.build(ItooResult.SUCCESS,"修改成功");
//        }
//        else {
//            return ItooResult.build(ItooResult.FAIL,"修改失败");
//        }
//    }
    //endregion

}    
